package com.example.mycontrols;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    ImageView image;
    EditText editText;
    ProgressBar progressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = findViewById(R.id.btn);
        button.setOnClickListener(this);
        image = findViewById(R.id.image);
        TextView tv = findViewById(R.id.text_view);
        //tv.setText(R.string.app_name);
        tv.setText("我的一个文本");
        editText = findViewById(R.id.edit_text);
        progressBar = findViewById(R.id.progressbar);


    }

    @Override
    public void onClick(View view) {
        image.setImageResource(R.drawable.img2);
        String inputText = editText.getText().toString();
        Toast.makeText(this,inputText,Toast.LENGTH_LONG).show();
        //对圆形滚动条方便设置可见或消失状态

//        if (progressBar.getVisibility() == View.GONE){
//            progressBar.setVisibility(View.VISIBLE);
//        }else{
//            progressBar.setVisibility(View.GONE);
//        }


        //点击按钮，每按一下，滚动条往前走一段
        int progress = progressBar.getProgress();
        progress += 10;
        progressBar.setProgress(progress);


      /*  AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("这是一个对话框");
        dialog.setMessage("这是一个消息内容");
        dialog.setCancelable(false);   //在对话框的外面点击不会消失，只有点击对话框里面的ok 或者cancel才消失
        dialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.show();

        */
           ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("this is a progressDialog");
        progressDialog.setMessage("Loading...");

      /* 自己不会消失，阻止了用户的其他操作，后台做完网络交互，用代码结束该对话框progressDialog.hide();
        */
        progressDialog.setCancelable(false);
        progressDialog.show();
    }
}